Repository navigation
Conversation
| ]; | ||
|
|
||
| function gryffindorHouse(hogwart) { | ||
| for ({ firstName, lastName, house } of hogwart) { |
There was a problem hiding this comment.
Something is missing in this loop header. Try running the file in strict mode ("use strict"; at the top) or look at what happens to firstName, lastName and house after the loop. Think about how you'd normally declare a loop variable.
There was a problem hiding this comment.
Thank you for your support it was really helpful! I have amended the code.
|
|
||
| function findPet(hogwart) { | ||
| for ({ firstName, lastName, pet } of hogwart) { | ||
| if (pet === "Phoenix") console.log(firstName, lastName); |
There was a problem hiding this comment.
Does this check match what the task asked for? Re-read the requirement: which two conditions does a character need to meet? Does the check here work for any teacher with a pet, or only for the one in this specific data set? What would happen if a second teacher had a different pet?
| let total = 0; | ||
| console.log(`${"QTY"} ${"ITEM"} ${"Total"}`); | ||
|
|
||
| for ({ itemName, quantity, unitPricePence } of orders) { |
There was a problem hiding this comment.
These variables aren't declared with anything. What would happen if this code ran in strict mode or inside an ES module?
| function findPet(hogwart) { | ||
| for (const { firstName, lastName, pet, occupation } of hogwart) { | ||
| if (pet && occupation === "Teacher") | ||
| console.log(`name of a teacher who has pet ${firstName} ${lastName}`); |
There was a problem hiding this comment.
Compare your output with the expected result in the task. What would the output look like if you ran this code? Does it match line for line?
There was a problem hiding this comment.
I will restore it to the original state only did that to differentiate it from the rest of the output. It was confusing.
| ); | ||
| } | ||
|
|
||
| console.log(`\nTotal:${total.toFixed(2)}`); |
There was a problem hiding this comment.
Run the program and look at the number printed after Total:. Compare it with the expected 14.50. What unit is total in, and what unit is toFixed(2) assuming? Also compare the text between Total: and the number with the expected output.
| let total = 0; | ||
| console.log(`${"QTY"} ${"ITEM"} ${"Total"}`); | ||
|
|
||
| for ({ itemName, quantity, unitPricePence } of orders) { |
|
|
||
| function receipt(orders) { | ||
| let total = 0; | ||
| console.log(`${"QTY"} ${"ITEM"} ${"Total"}`); |
There was a problem hiding this comment.
- Compare your header with the expected one, character by character: capitalisation of the last word, and the number of spaces between columns.
- Does the ITEM column in the header start at the same position as the item names in your rows? Print it and check by eye.
${"QTY"},${"ITEM"}and${"Total"}are all string literals being interpolated. Interpolation is for inserting values that vary (variables, expressions). What do these three give you over writing the text directly?
If the goal is to control column widths, is there a method you're already using in the rows that could build the header too?
There was a problem hiding this comment.
I have made the changes. Thank you!
| total += quantity * unitPricePence; | ||
|
|
||
| console.log( | ||
| `${quantity.toString().padEnd(4)} ${itemName.toString().padEnd(21)}${((quantity * unitPricePence) / 100).toFixed(2)}` |
There was a problem hiding this comment.
The header spacing and the row spacing are set in two different ways. If you changed a column width, how many places would you have to update? Can the header and rows share the same widths?
itemName.toString()
itemName is already a string here, so is this call doing anything?
Learners, PR Template
Self checklist
Task code
CYF-1112
Changelist
I have completed the task using object destructuring.
Questions